﻿using System.Collections.Generic;
using System.Linq;
using Android.App;
using Android.Views;
using Android.Widget;
using CapstoneProject.Models;

namespace CapstoneProject
{
    public class BankListAdapter : BaseAdapter
    {
        private IEnumerable<string> banks;
        private Activity context;

        public BankListAdapter(Activity context, IEnumerable<string> banks)
        {
            this.context = context;
            this.banks = banks;
        }

        public override View GetView(int position, View convertView, ViewGroup parent)
        {
            var view = (convertView
                            ?? context.LayoutInflater.Inflate(
                                    Resource.Layout.BankListItem, parent, false)
                        ) as LinearLayout;
            var bank = banks.ElementAt(position);

            view.FindViewById<TextView>(Resource.Id.BankName).Text = bank;

            return view;
        }

        public override int Count
        {
            get { return banks.Count(); }
        }

        public override Java.Lang.Object GetItem(int position)
        {
            return null;
        }

        public override long GetItemId(int position)
        {
            return position;
        }

        public string GetBank(int position)
        {
            return banks.ElementAt(position);
        }
    }
}
